package com.wzcl.app.model.vo;

import com.wzcl.app.dao.model.ActivityFullCutPromotion;
import com.wzcl.app.dao.model.ActivityGroupPromotion;
import com.wzcl.app.dao.model.ActivitySeckillPromotion;
import com.wzcl.app.dao.model.ActivitySinglePromotion;
import com.wzcl.app.dao.model.common.Promotion;
import com.wzcl.app.model.common.WZCL;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.beans.BeanUtils;

import java.math.BigDecimal;
import java.util.Map;

@EqualsAndHashCode(callSuper = true)
@Data
public class PromotionVo extends BaseVo {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "活动Id")
    private Integer activityId;

    //-------------满减-----------------
    @ApiModelProperty(value = "满减类型")
    private Integer fullCutType;
    private String fullCutTypeStr;

    @ApiModelProperty(value = "满价格值")
    private String fullPrice;

    @ApiModelProperty(value = "减价格值")
    private String cutPrice;

    //-----------单品/----------------
    @ApiModelProperty(value = "促销类型")
    private Integer promotionType;
    private String promotionTypeStr;

    @ApiModelProperty(value = "促销数值")
    private String value;

    //-----------秒杀特有-----------
    @ApiModelProperty(value = "秒杀数量")
    private Integer stock;

    //-----------排序------------------
    @ApiModelProperty(value = "排序字段")
    private Integer orderNo;

    //----------拼团特有---------------
    @ApiModelProperty(value = "满人数")
    private BigDecimal groupSize;

    @ApiModelProperty(value = "成团时间")
    private Long time;

    private PromotionVo(){

    }

    public static PromotionVo create(Promotion promotion){
        PromotionVo promotionVo = new PromotionVo();
        if(promotion instanceof  ActivityFullCutPromotion){
            ActivityFullCutPromotion fullCutPromotion = (ActivityFullCutPromotion) promotion;
            BeanUtils.copyProperties(fullCutPromotion,promotionVo,"fullPrice","cutPrice");
            promotionVo.fullPrice = fullCutPromotion.getFullPrice().setScale(2,BigDecimal.ROUND_DOWN).toString();
            promotionVo.cutPrice = fullCutPromotion.getCutPrice().setScale(2,BigDecimal.ROUND_DOWN).toString();
            promotionVo.translationValueStr();
            return promotionVo;
        }else if(promotion instanceof ActivitySinglePromotion){
            ActivitySinglePromotion singlePromotion = (ActivitySinglePromotion) promotion;
            BeanUtils.copyProperties(singlePromotion,promotionVo,"value");
            promotionVo.value = singlePromotion.getValue().setScale(2,BigDecimal.ROUND_DOWN).toString();
            promotionVo.translationValueStr();
            return promotionVo;
        }else if(promotion instanceof ActivitySeckillPromotion){
            ActivitySeckillPromotion singlePromotion = (ActivitySeckillPromotion) promotion;
            BeanUtils.copyProperties(singlePromotion,promotionVo,"value");
            promotionVo.value = singlePromotion.getValue().setScale(2,BigDecimal.ROUND_DOWN).toString();
            promotionVo.translationValueStr();
            return promotionVo;
        }else if(promotion instanceof ActivityGroupPromotion){
            ActivityGroupPromotion groupPromotion = (ActivityGroupPromotion) promotion;
            BeanUtils.copyProperties(groupPromotion,promotionVo,"value");
            promotionVo.value = groupPromotion.getValue().setScale(2,BigDecimal.ROUND_DOWN).toString();
            promotionVo.translationValueStr();
            return promotionVo;
        }
        return promotionVo;
    }

    @Override
    public void translationValueStr() {
        Map<String, Map<Integer, String>> map = getTranslationMap();
        if(this.fullCutType!=null){
            this.fullCutTypeStr = map.get(WZCL.GROUP_NAME.ACTIVITY_FULL_CUT_TYPE).get(this.fullCutType);
        }
        if(this.promotionType!=null){
            this.promotionTypeStr = map.get(WZCL.GROUP_NAME.ACTIVITY_PROMOTION_TYPE).get(this.promotionType);
        }
    }

    @Override
    public void processResources() {

    }
}
